import { NodeStatus } from "../NodeStatus";
import { DecoratorNode } from "./DecoratorNode";


/**
 * 如果子节点执行后返回RUNNING或SUCCESS，下次tick()继续执行子节点，直到子节点返回FAILURE。
 */
export class KeepRunningUntilFailureNode<T> extends DecoratorNode<T> {


    constructor(name: string, blackboard: T) {
        super(name, blackboard);
    }

    Tick(): NodeStatus {
        this.status = NodeStatus.RUNNING;

        const child_state = this.GetChild()!.Evaluate();

        switch (child_state) {
            case NodeStatus.FAILURE: {
                return NodeStatus.FAILURE;
            }
            case NodeStatus.SUCCESS:
            case NodeStatus.RUNNING: {
                return NodeStatus.RUNNING;
            }
        }
        return this.status;
    }
}